//
//  FeedBackViewController.m
//  jingdongfang
//
//  Created by 郝志宇 on 16/9/1.
//  Copyright © 2016年 ZhiYu Hao. All rights reserved.
//

#import "FeedBackViewController.h"
#import "SettingsViewController.h"
#import "IGFeedBackApi.h"

@interface FeedBackViewController ()<UITextViewDelegate>
@property (strong, nonatomic) IBOutlet UITextView *text;
@property(nonatomic,strong)IGFeedBackApi *FeedBackApi;
@end

@implementation FeedBackViewController
#pragma mark -生命周期
- (void)viewDidLoad {
    [super viewDidLoad];
//    self.title = @"意见反馈";
    self.title = NSLocalizedString(@"Feedback", nil);
//     _text.text = @"请输入反馈内容";
    _text.text = NSLocalizedString(@"Please Input Feedback Content", nil);
     _text.textColor = [UIColor c5Color];
     _text.delegate = self;
     self.automaticallyAdjustsScrollViewInsets=NO;
    
}
#pragma mark - UITextViewDelegate
- (void)textViewDidEndEditing:(UITextView *)textView
{
    if(_text.text.length < 1){
//        _text.text = @"请输入反馈内容";
        _text.text = NSLocalizedString(@"Please Input Feedback Content", nil);
        textView.textColor = [UIColor c5Color];
    }
}
- (void)textViewDidBeginEditing:(UITextView *)textView
{
    if([_text.text isEqualToString:NSLocalizedString(@"Please Input Feedback Content", nil)]){
        _text.text=@"";
        _text.textColor=[UIColor blackColor];
    }
}


- (IBAction)confirmBtnClick:(id)sender
{
    NSLog(@"你点击了确定按钮");
    [self loadFeedBack];
}

- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
{
    [self.view endEditing:YES];
}

- (void)loadFeedBack
{
    if([self.text.text isEqualToString:NSLocalizedString(@"Please Input Feedback Content", nil)]){
//       [self presentMessageTips:@"请输入反馈内容"];
        [self presentMessageTips:NSLocalizedString(@"Please Input Feedback Content", nil)];
        return;
    }
    self.FeedBackApi=[[IGFeedBackApi alloc]initWithuId:[IGUser getUid] content:self.text.text];
    [self.FeedBackApi startWithDecodeClass:[IGFeedBackResp class] CompletionBlockWithSuccess:^(id responseObject, NSError *error) {
        if (responseObject) {
//            [self presentMessageTips:@"发送成功"];
//            [self presentMessageTips:NSLocalizedString(@"Sent Successfully", nil)];
            [self presentMessageTips:NSLocalizedString(@"Thanks for your feedback!", nil)];
          [NSTimer scheduledTimerWithTimeInterval:1.0f target:self selector:@selector(pushVC) userInfo:nil repeats:NO];
         }else{
//            [self presentMessageTips:@"发送失败"];
             [self presentMessageTips:NSLocalizedString(@"Sending Failed", nil)];

        }
    }];
}
-(void)pushVC{

    [self.navigationController popViewControllerAnimated:YES];
//     [self.navigationController pushViewController:settingVC animated:YES ];
//     BOOL flag = NO;
//     NSMutableArray *array = [NSMutableArray array];
//     for (int i = 0; i < self.navigationController.viewControllers.count - 1; i ++)
//          {
//             UIViewController *vc = self.navigationController.viewControllers[i];
//             if (flag == NO && [vc isKindOfClass:[SettingsViewController class]])
//                {
//                  flag = YES;
//                }
//           if (flag)
//              {
//                 [array addObject:vc];
//               }
//           }
//      NSMutableArray *viewControllers = [NSMutableArray arrayWithArray:self.navigationController.viewControllers];
//      [viewControllers removeObjectsInArray:array];
//      self.navigationController.viewControllers = viewControllers;
   }
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
